home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj8409.arc / STRSEARC.ASM < prev    next >
Assembly Source File  |  1986-09-14  |  1KB  |  56 lines

  1. ;  ROUTINE TO SEARCH FOR ONE STRING WITHIN ANOTHER
  2. ;
  3. strsearch    proc    far
  4. ;
  5.     push    si        ; save registers
  6.     push    di
  7.     push    cx
  8. ;
  9. ; get length of destination and point to first byte
  10.     mov    si,dx        ; use source index
  11.     lodsw            ; get the length of destination
  12.     mov    cx,ax        ; use the length as a count
  13.     mov    dx,si        ; text begins here
  14. ;
  15. strsearch1:
  16. ; point indices to beginning of source and destination
  17.     mov    si,bx        ; load source index
  18.     mov    di,dx        ; load destination index
  19. ;
  20. ; scan for match
  21.     mov    al,[si+2]    ; get the first character
  22.     cld            ; forward direction
  23.     repnz    scasb        ; scan for match
  24.     jcxz    strsearch2    ; quit if found no match 
  25. ;
  26. ; got a match of first characters - now check the entire string
  27.     mov    dx,di        ; save current destination loc
  28.     dec    di        ; beginning of word
  29.     lodsw            ; get length of source
  30.     xchg    cx,ax        ; use source count and save dest count
  31.     repz    cmpsb        ; compare the two strings
  32.     jcxz    strsearch3    ; it's a match if no more source
  33. ;
  34. ; continue the scan
  35.     xchg    cx,ax        ; use destination count
  36.     jmp    strsearch1    ; back for more scanning of dest
  37. ;
  38. ; no match is possible
  39. strsearch2:
  40.     mov    al,0        ; unsuccessful outcome
  41.     jmp    strsearchexit
  42. ;
  43. ; found a match
  44. strsearch3:
  45.     dec    dx        ; point to beginning of match
  46.     mov    al,0FFh        ; successful match
  47.     jmp    strsearchexit
  48. ;
  49. strsearchexit:
  50.     pop    cx        ; restore registers
  51.     pop    di
  52.     pop    si
  53.     ret
  54. ;
  55. strsearch    endp
  56.